<?php
namespace Util;
class Curl{
	//get请求
	public static function http_get($url){
	    $ch = curl_init();
	    if(stripos($url,"https://")!==FALSE){
	        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	        curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
	    }
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
	    $content = curl_exec($ch);
	    $status = curl_getinfo($ch);
	    curl_close($ch);
	    if(intval($status["http_code"])==200){
	        return $content;
	    }else{
	        return false;
	    }
	}
		
	public static function http_post($url,$param,$post_file=false){
	    $ch = curl_init();
	    if(stripos($url,"https://")!==FALSE){
	        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	        curl_setopt($ch, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
	    }
	    if (is_string($param) || $post_file) {
	        $strPOST = $param;
	    } else {
	        $aPOST = array();
	        foreach($param as $key=>$val){
	            $aPOST[] = $key."=".urlencode($val);
	        }
	        $strPOST =  join("&", $aPOST);
	    }
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
	    curl_setopt($ch, CURLOPT_POST,true);
	    curl_setopt($ch, CURLOPT_POSTFIELDS,$strPOST);
	    $content = curl_exec($ch);
	    $status = curl_getinfo($ch);
	    curl_close($ch);
	    if(intval($status["http_code"])==200){
	        return $content;
	    }else{
	        return false;
	    }
	}
}